package com.sunwayhorizo.health.hl7.rim;

import static com.sunwayhorizo.health.hl7.vocabulary.EntityCdSetCode.*;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;

import org.jboss.seam.annotations.Name;

import com.sunwayhorizo.health.common.DataTypeUtil;
import com.sunwayhorizo.health.common.StrUtil;
import com.sunwayhorizo.health.hl7.common.Hl7Exception;
import com.sunwayhorizo.health.hl7.datatypes.CE;
import com.sunwayhorizo.health.hl7.datatypes.PQ;
import com.sunwayhorizo.health.hl7.datatypes.ST;
import com.sunwayhorizo.health.hl7.factories.ReferenceModifier;
import com.sunwayhorizo.health.hl7.persistent.RimCoreEntyCdSets;

@Name("Material")
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorValue("MAT")
public class Material extends Hl7Entity implements Serializable
{

//    @SuppressWarnings("unused")
//    @Transient
//    private CE FormCode;

    /**
     * 
     */
    private static final long serialVersionUID = 1L;


    public Material() throws Hl7Exception
    {
    }


    public Material(ReferenceModifier referencemodifier)
    {
        super(referencemodifier);
    }

    /**
     * 设置剂型
     * @param ce
     */
    public void setFormCode(CE ce)
    {
        if (null != ce && ce.codeSystemEnName() != null && ce.codeName() != null)
        {
            setRimCoreEntyCdSets(ce, FORMCODE);
        }
        else
        {
            if(StrUtil.isNotEmpty(ce.code().toString()) && !ce.code().toString().equals("<Null:NullFlavor: NI>"))
            {
                this.setMtFormCodeEtsId(ce.code().toString());
            }
        }
    }

    /**
     * 得到剂型
     * @return
     * @throws Hl7Exception
     */
    public CE getFormCode() throws Hl7Exception
    {
        if (this.getMtFormCodeEtsId().equals(FORMCODE.toString()))
        {
            for (RimCoreEntyCdSets entityCdSets : this.getEntyCdSetsList())
            {
                if (this.getMtFormCodeEtsId().equals(entityCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(entityCdSets);
                }
            }
        }
        else
            return DataTypeUtil.getCE(this.getMtFormCodeEtsId());
        return null;
    }
    
    /**
     * 设置药品标识
     * @param ce
     */
    public void setIndicatorCode(CE ce)
    {
        if (null != ce && ce.codeSystemEnName() != null && ce.codeName() != null)
        {
            setRimCoreEntyCdSets(ce, INDICATORCODE);
        }
        else
        {
            if(StrUtil.isNotEmpty(ce.code().toString()) && !ce.code().toString().equals("<Null:NullFlavor: NI>"))
            {
                this.setMtIndicatorCodeEtsId(ce.code().toString());
            }
        }
    }

    /**
     * 得到药品标识
     * @return
     * @throws Hl7Exception
     */
    public CE getIndicatorCode() throws Hl7Exception
    {
        if (this.getMtIndicatorCodeEtsId().equals(INDICATORCODE.toString()))
        {
            for (RimCoreEntyCdSets entityCdSets : this.getEntyCdSetsList())
            {
                if (this.getMtIndicatorCodeEtsId().equals(entityCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(entityCdSets);
                }
            }
        }
        else
            return DataTypeUtil.getCE(this.getMtIndicatorCodeEtsId());
        return null;
    }
    
    /**
     * 设置材料分类(药理分类)
     * @param ce 材料分类信息
     */
    public void setMtClassCode(CE ce)
    {
        if (null != ce && ce.codeSystemEnName() != null && ce.codeName() != null)
        {
            setRimCoreEntyCdSets(ce, MTCLASSCODE);
        }
        else
        {
            if(StrUtil.isNotEmpty(ce.code().toString()) && !ce.code().toString().equals("<Null:NullFlavor: NI>"))
            {
                this.setMtClassCodeEtsId(ce.code().toString());
            }
        }
    }


    /**
     * 得到材料分类
     * @return CE
     * @throws Hl7Exception
     */
    public CE getMtClassCode() throws Hl7Exception
    {
        if (this.getMtClassCodeEtsId().equals(MTCLASSCODE.toString()))
        {
            for (RimCoreEntyCdSets entityCdSets : this.getEntyCdSetsList())
            {
                if (this.getMtClassCodeEtsId().equals(entityCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(entityCdSets);
                }
            }
        }
        else
            return DataTypeUtil.getCE(this.getMtClassCodeEtsId());
        return null;
    }
    
    /**
     * 设置毒麻分类
     * @param ce 毒麻分类信息
     */
    public void setRiskCode(CE ce)
    {
        if (null != ce && ce.codeSystemEnName() != null && ce.codeName() != null)
        {
            setRimCoreEntyCdSets(ce, RISKCODE);
        }
        else
        {
            if(StrUtil.isNotEmpty(ce.code().toString()) && !ce.code().toString().equals("<Null:NullFlavor: NI>"))
            {
                this.setMtRiskCode(ce.code().toString());
            }
           
        }
    }


    /**
     * 得到毒麻分类
     * @return CE
     * @throws Hl7Exception
     */
    public CE getRiskCode() throws Hl7Exception
    {
        if (this.getMtRiskCode().equals(RISKCODE.toString()))
        {
            for (RimCoreEntyCdSets entityCdSets : this.getEntyCdSetsList())
            {
                if (this.getMtRiskCode().equals(entityCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(entityCdSets);
                }
            }
        }
        else
            return DataTypeUtil.getCE(this.getMtRiskCode());
        return null;
    }
    
    /**
     * 设置材料浓度
     * @param concentration PQ型浓度类型
     */
    public void setConcentration(PQ concentration)
    {
        this.setMtConcentrationQtyTex(concentration.value().literal().toString());
        this.setMtConcentrationUomCode(concentration.unit().code().toString());
    }

    /**
     * 得到材料浓度
     * @return
     * @throws Hl7Exception
     */
    public PQ getConcentration() throws Hl7Exception
    {
        return DataTypeUtil.getPQ(this.getMtConcentrationQtyTex(), this.getMtConcentrationUomCode());
    }
    
    /**
     * 设置体积
     * @param concentration PQ体积
     */
    public void setVolume(PQ concentration)
    {
        this.setMtVolumeQtyTex(concentration.value().literal().toString());
        this.setMtVolumeUomCode(concentration.unit().code().toString());
    }

    /**
     * 得到体积
     * @return
     * @throws Hl7Exception
     */
    public PQ getVolume() throws Hl7Exception
    {
        return DataTypeUtil.getPQ(this.getMtVolumeQtyTex(), this.getMtVolumeUomCode());
    }
    
    /**
     * 设置重量
     * @param concentration PQ重量
     */
    public void setWeigh(PQ weiht)
    {
        this.setMtWeighQtyTex(weiht.value().literal().toString());
        this.setMtWeighUomCode(weiht.unit().code().toString());
    }

    /**
     * 得到重量
     * @return
     * @throws Hl7Exception
     */
    public PQ getWeigh() throws Hl7Exception
    {
        return DataTypeUtil.getPQ(this.getMtWeighQtyTex(), this.getMtWeighUomCode());
    }
    
    /**
     * 设置材料限制级别
     * @param ce 材料限制级别信息
     */
    public void setMtLimitedLevel(CE ce)
    {
        if (null != ce && ce.codeSystemEnName() != null && ce.codeName() != null)
        {
            setRimCoreEntyCdSets(ce, MTLIMITEDLEVEL);
        }
        else
        {
            if(StrUtil.isNotEmpty(ce.code().toString()) && !ce.code().toString().equals("<Null:NullFlavor: NI>"))
            {
                this.setMtLimitedLevelEtsId(ce.code().toString());
            }
          
        }
    }


    /**
     * 得到材料限制级别
     * @return CE
     * @throws Hl7Exception
     */
    public CE getMtLimitedLevel() throws Hl7Exception
    {
        if (this.getMtLimitedLevelEtsId().equals(MTLIMITEDLEVEL.toString()))
        {
            for (RimCoreEntyCdSets entityCdSets : this.getEntyCdSetsList())
            {
                if (this.getMtLimitedLevelEtsId().equals(entityCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(entityCdSets);
                }
            }
        }
        else
            return DataTypeUtil.getCE(this.getMtLimitedLevelEtsId());
        return null;
    }
    
    /**
     * 设置皮试标志
     * @param mtSkintestFlag 
     */
    public void setSkintestFlag(ST mtSkintestFlag)
    {
        this.setMtSkintestFlag(mtSkintestFlag.stringValue());
    }
    
    /**
     * 得到皮试标志
     * @return
     * @throws Hl7Exception
     */
    public ST getSkintestFlag() throws Hl7Exception
    {
        return DataTypeUtil.getST(this.getMtSkintestFlag());
    }
    
    /**
     * 设置OTC标志
     * @param otcFlag
     */
    public void setOtcFlag(ST otcFlag)
    {
        this.setMtOtcFlag(otcFlag.stringValue());
    }
    
    /**
     * 得到OTC标志
     * @return
     * @throws Hl7Exception
     */
    public ST getOtcFlag() throws Hl7Exception
    {
        return DataTypeUtil.getST(this.getMtOtcFlag());
    }
    
    /**
     * 设置违禁标志
     * @param contrabandFlag
     */
    public void setContrabandFlag(ST contrabandFlag)
    {
        this.setMtContrabandFlag(contrabandFlag.stringValue());
    }
    
    /**
     * 得到违禁标志
     * @return ST
     * @throws Hl7Exception
     */
    public ST getContrabandFlag() throws Hl7Exception
    {
        return DataTypeUtil.getST(this.getMtContrabandFlag());
    }
    
    /**
     * 设置贵重标志
     * @param valuableFlag
     * @return
     */
    public void setValuableFlag(ST valuableFlag)
    {
        this.setMtValuableFlag(valuableFlag.stringValue());
    }
    
    /**
     * 得到违禁标志
     * @return
     * @throws Hl7Exception
     */
    public ST getValuableFlag() throws Hl7Exception
    {
        return DataTypeUtil.getST(this.getMtValuableFlag());
    }
    
    /**
     * 设置批准文号
     * @param approvalFlag
     */
    public void setApprovalFlag(ST approvalFlag)
    {
        this.setMtApprovalFlag(approvalFlag.stringValue());
    }
    
    /**
     * 设置医保分类
     * @param ce 医保分类
     */
    public void setInsuranceClassCode(CE ce)
    {
        if (null != ce && ce.codeSystemEnName() != null && ce.codeName() != null)
        {
            setRimCoreEntyCdSets(ce, INSURANCECLASSCODE);
        }
        else
        {
            if(StrUtil.isNotEmpty(ce.code().toString()) && !ce.code().toString().equals("<Null:NullFlavor: NI>"))
            {
                this.setMtInsuranceClassEtsId(ce.code().toString());
            }
        }
    }


    /**
     * 得到医保分类
     * @return CE
     * @throws Hl7Exception
     */
    public CE getInsuranceClassCode() throws Hl7Exception
    {
        if (this.getMtInsuranceClassEtsId().equals(INSURANCECLASSCODE.toString()))
        {
            for (RimCoreEntyCdSets entityCdSets : this.getEntyCdSetsList())
            {
                if (this.getMtInsuranceClassEtsId().equals(entityCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(entityCdSets);
                }
            }
        }
        else
            return DataTypeUtil.getCE(this.getMtInsuranceClassEtsId());
        return null;
    }
    
    /**
     * 设置医保编号
     * @param insuranceCode 医保编号
     */
    public void setInsuranceCode(ST insuranceCode)
    {
        this.setMtInsuranceCode(insuranceCode.stringValue());
    }
    
    /**
     * 得到医保编号
     * @return ST
     * @throws Hl7Exception
     */
    public ST getInsuranceCode() throws Hl7Exception
    {
        return DataTypeUtil.getST(this.getMtInsuranceCode());
    }
    
   
    
    
    /**
     * 得到批准文号
     * @return ST
     * @throws Hl7Exception
     */
    public ST getApprovalFlag() throws Hl7Exception
    {
        return DataTypeUtil.getST(this.getMtApprovalFlag());
    }
    
    /**
     * 设置药品条码
     * @param barCode
     */
    public void setBarCode(ST barCode)
    {
        if(barCode == null || barCode.isNull().isTrue()) return;
        this.setMtBarCode(barCode.stringValue());
    }
    
    /**
     * 得到药品条码
     * @return
     * @throws Hl7Exception
     */
    public ST getBarCode() throws Hl7Exception
    {
        return DataTypeUtil.getST(this.getMtBarCode());
    }
    
    /**
     * 设置材料来源
     * @param ce 材料来源
     */
    public void setMadeBY(CE ce)
    {
        if (null != ce && ce.codeSystemEnName() != null && ce.codeName() != null)
        {
            setRimCoreEntyCdSets(ce, MTMADEBY);
        }
        else
        {
            if(StrUtil.isNotEmpty(ce.code().toString()) && !ce.code().toString().equals("<Null:NullFlavor: NI>"))
            {
                this.setMtMadeByEtsId(ce.code().toString());
            }
        }
    }


    /**
     * 得到材料来源
     * @return CE
     * @throws Hl7Exception
     */
    public CE getMadeBY() throws Hl7Exception
    {
        if (this.getMtMadeByEtsId().equals(MTMADEBY.toString()))
        {
            for (RimCoreEntyCdSets entityCdSets : this.getEntyCdSetsList())
            {
                if (this.getMtMadeByEtsId().equals(entityCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(entityCdSets);
                }
            }
        }
        else
            return DataTypeUtil.getCE(this.getMtMadeByEtsId());
        return null;
    }
    
    /**
     * 设置招标标志
     * @param bidFlag
     */
    public void setBidFlag(ST bidFlag)
    {
        this.setMtBidFlag(bidFlag.stringValue());
    }
    
    /**
     * 得到招标标志
     * @return
     * @throws Hl7Exception
     */
    public ST getBidFlag() throws Hl7Exception
    {
        return DataTypeUtil.getST(this.getMtBidFlag());
    }
    
    /**
     * 设置GMP标志
     * @param gmpFlag
     */
    public void setGmpFlag(ST gmpFlag)
    {
        this.setMtGmpFlag(gmpFlag.stringValue());
    }
    
    /**
     * 得到GMP标志
     * @return
     * @throws Hl7Exception
     */
    public ST getGmpFlag() throws Hl7Exception
    {
        return DataTypeUtil.getST(this.getMtGmpFlag());
    }
    
    /**
     * 设置厂家
     * @param ce 厂家
     */
    public void setManufcturerCode(CE ce)
    {
        if (null != ce && ce.codeSystemEnName() != null && ce.codeName() != null)
        {
            setRimCoreEntyCdSets(ce, MANUFCTURERCODE);
        }
        else
        {
            if(StrUtil.isNotEmpty(ce.code().toString()) && !ce.code().toString().equals("<Null:NullFlavor: NI>"))
            {
                this.setMtManufcturerCodeEtsId(ce.code().toString());
            }
        }
    }


    /**
     * 得到厂家
     * @return CE
     * @throws Hl7Exception
     */
    public CE getManufcturerCode() throws Hl7Exception
    {
        if (this.getMtManufcturerCodeEtsId().equals(MANUFCTURERCODE.toString()))
        {
            for (RimCoreEntyCdSets entityCdSets : this.getEntyCdSetsList())
            {
                if (this.getMtManufcturerCodeEtsId().equals(entityCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(entityCdSets);
                }
            }
        }
        else
            return DataTypeUtil.getCE(this.getMtManufcturerCodeEtsId());
        return null;
    }
    
    

    // Material
    
    
    @Column(name = "MT_INDICATOR_ETS_ID")
    private String mtIndicatorCodeEtsId = INDICATORCODE.toString(); //药品标识
    
    @Column(name = "MT_FORM_CODE_ETS_ID")
    private String mtFormCodeEtsId = FORMCODE.toString(); //剂型
    
    @Column(name = "MT_CLASS_ETS_ID")
    private String mtClassCodeEtsId = MTCLASSCODE.toString(); //材料分类
    
    @Column(name = "MT_RISK_CODE_ETS_ID")
    private String mtRiskCode = RISKCODE.toString(); //毒麻分类
    
    //毒麻分类
    
    @Column(name = "MT_CONCENTRATION_QTY_TXT")
    private String mtConcentrationQtyTex ; //浓度
    
    @Column(name = "MT_CONCENTRATION_UOM_CODE")
    private String mtConcentrationUomCode ; //浓度单位
    
    @Column(name = "MT_VOLUME_QTY_TXT")
    private String mtVolumeQtyTex ; //体积
    
    @Column(name = "MT_VOLUME_QTY_UOM_CODE")
    private String mtVolumeUomCode ; //体积单位
    
    @Column(name = "MT_WEIGH_QTY_TXT")
    private String mtWeighQtyTex ; //重量
    
    @Column(name = "MT_WEIGH_QTY_UOM_CODE")
    private String mtWeighUomCode ; //重量单位
    
    @Column(name = "MT_LIMITED_LEVEL")
    private String mtLimitedLevelEtsId = MTLIMITEDLEVEL.toString(); //限制使用级别
    
    @Column(name = "MT_SKINTEST_FLAG")
    private String mtSkintestFlag ; //皮试标志
    
    @Column(name = "MT_OTC_FLAG")
    private String mtOtcFlag ; //OTC标志
    
    @Column(name = "MT_CONTRABAND_FLAG")
    private String mtContrabandFlag ; //违禁标志
    
    @Column(name = "MT_INSURANCE_CLASS_ETS_ID")
    private String mtInsuranceClassEtsId = INSURANCECLASSCODE.toString(); //医保分类
    
    @Column(name = "MT_INSURANCE_CODE")
    private String mtInsuranceCode ; //医保编码
    
    

    
    
    

    @Column(name = "MT_VALUABLE_FLAG")
    private String mtValuableFlag ; //贵重标志
    
    @Column(name = "MT_APPROVAL_NUMBER")
    private String mtApprovalFlag ; //批准文号
    
    @Column(name = "MT_BAR_CODE")
    private String mtBarCode ; //药品条码
    
    @Column(name = "MT_MADE_BY")
    private String mtMadeByEtsId = MTMADEBY.toString() ; //国产，进口，自制
    
    @Column(name = "MT_BID_FLAG")
    private String mtBidFlag ; //招标标志
    
    @Column(name = "MT_GMP_FLAG")
    private String mtGmpFlag ; //GMP标志
    
    @Column(name = "MT_MANUFACTURER_CODE_ETS_ID")
    private String mtManufcturerCodeEtsId = MANUFCTURERCODE.toString() ; //厂家
    
    

    

    private void setMtFormCodeEtsId(String mtFormCodeEtsId)
    {
        this.mtFormCodeEtsId = mtFormCodeEtsId;
    }


    private String getMtFormCodeEtsId()
    {
        return mtFormCodeEtsId;
    }


    private String getMtClassCodeEtsId()
    {
        return mtClassCodeEtsId;
    }


    private void setMtClassCodeEtsId(String mtClassCodeEtsId)
    {
        this.mtClassCodeEtsId = mtClassCodeEtsId;
    }


    private String getMtConcentrationQtyTex()
    {
        return mtConcentrationQtyTex;
    }


    private void setMtConcentrationQtyTex(String mtConcentrationQtyTex)
    {
        this.mtConcentrationQtyTex = mtConcentrationQtyTex;
    }


    private String getMtConcentrationUomCode()
    {
        return mtConcentrationUomCode;
    }


    private void setMtConcentrationUomCode(String mtConcentrationUomCode)
    {
        this.mtConcentrationUomCode = mtConcentrationUomCode;
    }


    private String getMtVolumeQtyTex()
    {
        return mtVolumeQtyTex;
    }


    private void setMtVolumeQtyTex(String mtVolumeQtyTex)
    {
        this.mtVolumeQtyTex = mtVolumeQtyTex;
    }


    private String getMtVolumeUomCode()
    {
        return mtVolumeUomCode;
    }


    private void setMtVolumeUomCode(String mtVolumeUomCode)
    {
        this.mtVolumeUomCode = mtVolumeUomCode;
    }


    private String getMtWeighQtyTex()
    {
        return mtWeighQtyTex;
    }


    private void setMtWeighQtyTex(String mtWeighQtyTex)
    {
        this.mtWeighQtyTex = mtWeighQtyTex;
    }


    private String getMtWeighUomCode()
    {
        return mtWeighUomCode;
    }


    private void setMtWeighUomCode(String mtWeighUomCode)
    {
        this.mtWeighUomCode = mtWeighUomCode;
    }


    private String getMtLimitedLevelEtsId()
    {
        return mtLimitedLevelEtsId;
    }


    private void setMtLimitedLevelEtsId(String mtLimitedLevelEtsId)
    {
        this.mtLimitedLevelEtsId = mtLimitedLevelEtsId;
    }


    private String getMtSkintestFlag()
    {
        return mtSkintestFlag;
    }


    private void setMtSkintestFlag(String mtSkintestFlag)
    {
        this.mtSkintestFlag = mtSkintestFlag;
    }


    private String getMtOtcFlag()
    {
        return mtOtcFlag;
    }

    private void setMtOtcFlag(String mtOtcFlag)
    {
        this.mtOtcFlag = mtOtcFlag;
    }


    private String getMtContrabandFlag()
    {
        return mtContrabandFlag;
    }

    private void setMtContrabandFlag(String mtContrabandFlag)
    {
        this.mtContrabandFlag = mtContrabandFlag;
    }


    private String getMtValuableFlag()
    {
        return mtValuableFlag;
    }


    private void setMtValuableFlag(String mtValuableFlag)
    {
        this.mtValuableFlag = mtValuableFlag;
    }


    private String getMtApprovalFlag()
    {
        return mtApprovalFlag;
    }

    private void setMtApprovalFlag(String mtApprovalFlag)
    {
        this.mtApprovalFlag = mtApprovalFlag;
    }


    private String getMtBarCode()
    {
        return mtBarCode;
    }


    private void setMtBarCode(String mtBarCode)
    {
        this.mtBarCode = mtBarCode;
    }


    private String getMtMadeByEtsId()
    {
        return mtMadeByEtsId;
    }


    private void setMtMadeByEtsId(String mtMadeByEtsId)
    {
        this.mtMadeByEtsId = mtMadeByEtsId;
    }


    private String getMtBidFlag()
    {
        return mtBidFlag;
    }


    private void setMtBidFlag(String mtBidFlag)
    {
        this.mtBidFlag = mtBidFlag;
    }


    private String getMtGmpFlag()
    {
        return mtGmpFlag;
    }

    private void setMtGmpFlag(String mtGmpFlag)
    {
        this.mtGmpFlag = mtGmpFlag;
    }


    private String getMtManufcturerCodeEtsId()
    {
        return mtManufcturerCodeEtsId;
    }


    private void setMtManufcturerCodeEtsId(String mtManufcturerCodeEtsId)
    {
        this.mtManufcturerCodeEtsId = mtManufcturerCodeEtsId;
    }


    private String getMtInsuranceClassEtsId()
    {
        return mtInsuranceClassEtsId;
    }


    private void setMtInsuranceClassEtsId(String mtInsuranceClassEtsId)
    {
        this.mtInsuranceClassEtsId = mtInsuranceClassEtsId;
    }


    private String getMtInsuranceCode()
    {
        return mtInsuranceCode;
    }


    private void setMtInsuranceCode(String mtInsuranceCode)
    {
        this.mtInsuranceCode = mtInsuranceCode;
    }


    private String getMtRiskCode()
    {
        return mtRiskCode;
    }


    private void setMtRiskCode(String mtRiskCode)
    {
        this.mtRiskCode = mtRiskCode;
    }


    private String getMtIndicatorCodeEtsId()
    {
        return mtIndicatorCodeEtsId;
    }


    private void setMtIndicatorCodeEtsId(String mtIndicatorCodeEtsId)
    {
        this.mtIndicatorCodeEtsId = mtIndicatorCodeEtsId;
    }
    
    

}
